/**
 * 
 */
package com.sssoft.Yundian.Dao;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.sssoft.Yundian.activity.MyIncomeActivity;
import com.sssoft.Yundian.bean.IncomeBean;

import android.R.string;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.print.PrintAttributes;
import android.widget.Toast;

/**
 * @author 我的收入页及订单详情页数据查询
 *
 */
public class IncomeDao {
	private MyHelper IncomeHelper;
	private SQLiteDatabase db;

	public IncomeDao(Context context) {
		IncomeHelper = new MyHelper(context);
	}

	// 获取总收入
	public String income_all() {
		double AllIncome = 0.0;
		String s = "";
		db = IncomeHelper.getWritableDatabase();
		Cursor cursor = db.rawQuery("select * from orders", null);
		while (cursor.moveToNext()) {
			String ord_income = cursor.getString(cursor.getColumnIndex("orders_total_price"));
			Double a = Double.valueOf(ord_income);
			AllIncome = AllIncome + a;
			s = String.valueOf(AllIncome);
		}
		cursor.close();
		db.close();
		return s;
	}

	

	// 获取全部收入数据
	public List<IncomeBean> queryAll() {
		// String sql = "select * from orders";
		db = IncomeHelper.getWritableDatabase();
		Cursor c = db.query("orders", null, null, null, null, null, "orders_id DESC");
//		Cursor c1 = db.rawQuery("select to_char(SYSDATE,'yyyymmdd') from orders",null);
		List<IncomeBean> list = new ArrayList<IncomeBean>();
		while (c.moveToNext()) {
			long id = c.getLong(c.getColumnIndex("orders_id"));
			String orders_number = c.getString(c.getColumnIndex("orders_number"));
			String orders_state = c.getString(c.getColumnIndex("orders_state"));
			String orders_date = c.getString(c.getColumnIndex("orders_date"));
			String orders_method = c.getString(c.getColumnIndex("orders_method"));
			String orders_total_price = c.getString(c.getColumnIndex("orders_total_price"));
			String orders_actual_price = c.getString(c.getColumnIndex("orders_actual_price"));
			String orders_details_change = c.getString(c.getColumnIndex("orders_details_change"));
			IncomeBean ib = new IncomeBean(id, orders_number, orders_state, orders_date, orders_method,
					orders_total_price, orders_actual_price, orders_details_change);
			list.add(ib);

		}
		c.close();
		db.close();
		return list;
	}
	// 获取订单详情listview数据-订单详情页
		public List<IncomeBean> list_goods_details(String orders_number) {
			db = IncomeHelper.getWritableDatabase();
			String sql = "select * from goods_details where orders_number=?";
			Cursor cu = db.rawQuery(sql, new String[] { orders_number });
			List<IncomeBean> goods_list = new ArrayList<IncomeBean>();
			while (cu.moveToNext()) {
				String goods_name = cu.getString(cu.getColumnIndex("goods_name"));
				String goods_price = cu.getString(cu.getColumnIndex("goods_price"));
				String goods_details_num = cu.getString(cu.getColumnIndex("goods_details_num"));
				String goods_details_total_price = cu.getString(cu.getColumnIndex("goods_details_total_price"));
				IncomeBean ibean = new IncomeBean(goods_name, goods_price, goods_details_num, goods_details_total_price);
				goods_list.add(ibean);

			}
			cu.close();
			db.close();
			return goods_list;

		}
		//退款时修改数据
//		public Boolean order_alter(String order_num){
//			db = IncomeHelper.getWritableDatabase();
//			
//			Cursor cur = db.rawQuery("select * from ", selectionArgs)
//		}

}
